# Gilardi, Fabrizio, "The Temporary Importance of Role Models for Women's Political Representation", American Journal of Political Science
# Code to replicate Table SI15 (Replication of Table 1, with an alternative dependent variable (percent women candidates))
# gilardi@ipz.uzh.ch, 2014-06-24

# Set working directory
setwd("../Data/")

# Load packages
library(texreg)

# Load data
d <- read.csv("dataset-full.csv")

# Compute new variables
d$pcent.women.cand.previously.elected <- d$n.women.cand.previously.elected/d$n.cand
d$pcent.men.cand.previously.elected <- d$n.men.cand.previously.elected/d$n.cand


###################
# Estimate models #########################################
###################

out.1w <- lm(pcent.women.cand ~ sl.autob.pcent.women.elected + pcent.women.elected.lagged + pcent.women.cand.previously.elected + pcent.men.cand.previously.elected + pcent.women.cand.lagged + n.people.elected + n.cand + referenda + wom.kr + log.dist.zh + log.pop + kr.svp + steuerfuss + as.factor(stadt.land) + as.factor(year), data=d)
summary(out.1w)

out.2w <- lm(pcent.women.cand ~ sl.autob.pcent.women.elected + pcent.women.elected.lagged + pcent.women.cand.previously.elected + pcent.men.cand.previously.elected + pcent.women.cand.lagged + n.people.elected + n.cand + referenda + wom.kr + log.dist.zh + log.pop + kr.svp + steuerfuss + as.factor(stadt.land) + sl.autob.pcent.women.elected*as.factor(year), data=d)
summary(out.2w)

out.3w <- lm(pcent.women.cand ~ sl.autob.pcent.women.elected + pcent.women.elected.lagged + pcent.women.cand.previously.elected + pcent.men.cand.previously.elected + pcent.women.cand.lagged + n.people.elected + n.cand + referenda + wom.kr + log.dist.zh + log.pop + kr.svp + steuerfuss + as.factor(stadt.land) + pcent.women.elected.lagged *as.factor(year), data=d)
summary(out.3w)

out.4w <- lm(pcent.women.cand ~ sl.autob.pcent.women.elected + pcent.women.elected.lagged + pcent.women.cand.previously.elected + pcent.men.cand.previously.elected + pcent.women.cand.lagged + n.people.elected + n.cand + referenda + wom.kr + log.dist.zh + log.pop + kr.svp + steuerfuss + as.factor(stadt.land) + sl.autob.pcent.women.elected*as.factor(year) + pcent.women.elected.lagged *as.factor(year), data=d)
summary(out.4w)

##############
# Make table ########################################
##############

var.names <- c(
	"(Intercept)",
	"Spatial lag",
	"$pc$ xfemale elected ($t-1$)",
	"$pc$ xfemale incumbent cand. ($t-1$)",
	"$pc$ xmale incumbent cand. ($t-1$)",
	"$pc$ xfemale cand. ($t-1$)",
	"Nr. seats",
	"Total nr. candidates",
	"Referenda on gender equality",
	"Support for xfemale in cantonal elec.",
	"Distance from Zurich (log)",
	"Population (log)",
	"Support for conservative party",
	"Tax level",
	"Suburb",
	"Countryside",
	seq(1978, 2010, 4),
	"Spatial lag $xx$ 1978",
	"Spatial lag $xx$ 1982",
	"Spatial lag $xx$ 1986",
	"Spatial lag $xx$ 1990",
	"Spatial lag $xx$ 1994",
	"Spatial lag $xx$ 1998",
	"Spatial lag $xx$ 2002",
	"Spatial lag $xx$ 2006",
	"Spatial lag $xx$ 2010",
	"$pc$ xfemale elected ($t-1$) $xx$ 1978",	
	"$pc$ xfemale elected ($t-1$) $xx$ 1982",	
	"$pc$ xfemale elected ($t-1$) $xx$ 1986",	
	"$pc$ xfemale elected ($t-1$) $xx$ 1990",	
	"$pc$ xfemale elected ($t-1$) $xx$ 1994",	
	"$pc$ xfemale elected ($t-1$) $xx$ 1998",	
	"$pc$ xfemale elected ($t-1$) $xx$ 2002",	
	"$pc$ xfemale elected ($t-1$) $xx$ 2006",	
	"$pc$ xfemale elected ($t-1$) $xx$ 2010"
)

model.names <- c("(1)", "(2)", "(3)", "(4)")

texreg(list(out.1w, out.2w, out.3w, out.4w), single.row=T, center=T, dcolumn=T, custom.coef.names=var.names, custom.model.names=model.names)







